package com.cn.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.cn.pojo.Car;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * 单独定义配置类,从jdbc.properties配置文件读取数据
 */
public class JdbcConfig1 {
    @Value("${db.driver}")
    private String driver;
    @Value("${db.url}")
    private String url;
    @Value("${db.username}")
    private String  username;
    @Value("${db.password}")
    private String password;
    @Bean
    public DataSource dataSource(Car car1){
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName(driver);
        druidDataSource.setUrl(url);
        druidDataSource.setUsername(username);
        druidDataSource.setPassword(password);
        System.out.println(password);
        System.out.println(car1.getCarBrand());
        return druidDataSource;
    }

}
